/**
 * udes.ds.rmi
 * SummativeEquation.java
 * 3 sept. 08
 */
package ift605.tp3.utils.equations;

import java.math.BigDecimal;

/**
 * Stores an equation of the type f(x) + g(x)
 * 
 * @author Luc Bergevin
 * @version 1.0
 */
public class SummativeEq extends AbstractEq implements IComplexEquation, IBinaireEquation
{
    
    private static final long serialVersionUID = 1L;
    private final IEquation _first;
    private final IEquation _second;
    
    public SummativeEq(IEquation first, IEquation second)
    {
        super();
        _first = first;
        _second = second;
    }
    
    public IEquation getFirst()
    {
        return _first;
    }
    
    public IEquation getSecond()
    {
        return _second;
    }
    
    /**
     * @see udes.ds.IEquation.hw.Equation#getFunctionValue(double)
     */
    public double getFunctionValue(double x)
    {
        return (_first.getFunctionValue(x) + _second.getFunctionValue(x));
    }
    
    /**
     * @see udes.ds.rmi.hw.AbstractEq#getUserReadableString()
     */
    @Override
    public String getUserReadableString()
    {
        return new String(_first.getUserReadableString() + " + " + _second.getUserReadableString());
    }
    
    @Override
    public IEquation getF()
    {
        return getFirst();
    }
    
    @Override
    public IEquation getG()
    {
        return getSecond();
    }
    
    @Override
    public BigDecimal eval(BigDecimal x)
    {
        return _first.eval(x).add(_second.eval(x));
    }
    
}
